<!--suppress ALL -->
<template>
<div class="page filesLib-page" data-page="filesLib" style="z-index: 2;">
	<div class="link-page-nav">
		<a href="#" class="link" @click="$root.backToTab()"> <i
			class="iconfont icon-zuo"></i>
		</a>
	</div>
	<div class="link-page-top">
		<div class="link-page-list-title" style="float: left;">档案</div>
		<div class="link-page-search"></div>
		<a href="#" class="link popover-open" data-popover="#filesLibList_menu" style="color: #000;"> 
			<i class="iconfont icon-APPicon_shaixuan1
" id="active" style="font-size: 23px;"></i>
		</a>
	</div>
	<div class="page-content" style="padding-bottom: 120px;">
		<div
			class="page-content infinite-scroll-content ptr-content pdbottom120"
			style="margin-top: 0;" data-infinite-distance="50"
			@infinite="loadMore" @ptr:refresh="refreshFilesLibList">
			<div class="ptr-preloader">
				<div class="preloader color-multi"></div>
				<div class="ptr-arrow"></div>
			</div>
			<div class="filesLib-list">
				<ul id="filesLib_list">
				</ul>
				<div id="filesLibList_preloader"
					class="preloader infinite-scroll-preloader"></div>
			</div>
		</div>
	</div>
	<div class="popover select-option-list" id="filesLibList_menu"
		style="width: 160px; top: 60px;">
		<div class="popover-angle"></div>
		<div class="popover-inner">
			<div class="list">
				<ul>
					<li><a href="" class="list-button item-link popover-close"
						id="select_org">选择单位</a></li>
					<a href=""
						class="list-button item-link popover-close removeScreen select-active"
						@click="removeScreen">清&nbsp&nbsp&nbsp&nbsp&nbsp空</a>
					</li>
				</ul>
			</div>
		</div>
	</div>
</div>
</div>
</template>
<script>
	return {
		data : function() {
			return {
				pageSize : 25,
				pageIndex : 0,
				name:'',
				orgIds : userInfor.organizationIds,
				selectOptionOrg:"",
			}
		},
		methods : {
			gatUnitList : function() {
				var self = this;
                //筛选按钮有值变色
				if(jQuery("#select_org")[0].innerText != "选择单位"){
                    jQuery("#active").addClass("select-active");
                }else{
                    jQuery("#active").removeClass("select-active");
                }
				Dao.getUcttuInfoForLogo({
					organizationIds : self.orgIds,
					pageIndex : self.pageIndex,
					pageSize : self.pageSize,
					queryType : 1,
					name : self.name,
				}, function(data,total) {
					$("#filesLib_list").empty();
					if (data && data.length > 0) {
						if (self.pageSize * self.pageIndex + data.length < total) { //有分页
							$("#filesLibList_preloader").show();
							self.allowInfinite = true;
						} else {
							$("#filesLibList_preloader").hide();
							self.allowInfinite = false;
						}
						for (var i = 0; i < data.length; i++) {
							$("#filesLib_list").append(`
							<a href="#" id="jump_to_filesLibDetail_`+data[i].organizationId+`">
								<li class="filesLib-org-item">
									<div class="item1">
										<p>`+data[i].shortName+`</p>
										<p>
											<span>`+data[i].address+`</span>
										</p>
									</div>
									<div class="item2" id="filesLib_`+data[i].organizationId+`"></div>
								</li>
							</a>`);
							//展示图片
							showImage(jQuery("#filesLib_"+data[i].organizationId),data[i].logoUrl,2);
							//跳转
							jQuery("#jump_to_filesLibDetail_"+data[i].organizationId).off().on("click",{'res':data[i]},function(e) {
								app.router.navigate(`/filesLibDetail/` + e.data.res.organizationId + `/`);
							})
						}
					} else {
						self.allowInfinite = false;
	            	    $("#filesLibList_preloader").hide();
	            		//暂无数据
		                if (self.pageIndex == 0) {
		                  	$("#filesLib_list").append(`<div class="no-data-img"><img src="`+listNoDataPic()+`"/></div>`);
		                }
					}
				}, true);
			},
			
			htmlPage:function(){
				var self = this;
	               jQuery("#select_org").off().click(function(e) {
	                   loadSelectUnitFunc(function(data){
	                       //筛选选中联网单位
	                       if(self.selectOptionOrg != data.orgId){
	                    	   self.selectOptionOrg=data.orgId;
							   self.orgIds=data.orgId;
							    jQuery("#select_org").html(data.orgName);
                                jQuery("#select_org").addClass('select-active');
	                       } else {
							   self.selectOptionOrg = 0;
							    jQuery("#select_org").html("选择单位");
                                jQuery("#select_org").removeClass('select-active');
	                           if (single_Orgid == "") {
	                             self.orgIds=userInfor.organizationIds;
	                           } else {
	                             self.orgIds=single_Orgid;
	                           }
	                       }
	                       self.pageIndex = 0;
	                       self.reInit();
	                       self.gatUnitList();
	                   },self.selectOptionOrg);
	               });
			},
			
			loadMore : function() {
				var self = this;
				if (!self.allowInfinite)
					return;
				self.allowInfinite = false;
				setTimeout(function() {
					self.pageIndex++;
					self.gatUnitList();
					self.allowInfinite = true;
				}, 1000);
			},
			reInit : function() {
				var self = this;
				self.pageIndex = 0;
				if (app.view.current.router.url.indexOf('/filesLib/') > -1) {//防止子页面返回触发。有类似的需求可以往这个里面添加
					$(".page-content").scrollTop(0, 300);
				}
				$("#filesLib_list").empty();
				if (!self.allowInfinite) {
					self.allowInfinite = true;
					$('#delayTaskList_preloader').show();
				}
			},
			refreshFilesLibList : function(e, done) {
				if (done && e) {
					var self = this;
					var $ = self.$$;
					setTimeout(function() {
						self.reInit();
						$('#filesLibList_preloader').hide();
						self.gatUnitList();
						done();
					}, 1000);
				}
			},
			
			removeScreen:function(){
				var self = this;
				jQuery("#select_org").removeClass('select-active').html("选择单位");
				self.pageIndex = 0;
				 if (userInfor.isMuilUnitUser  == 0) {
		       		  self.orgIds = userInfor.organizationIds;
		       	  }else{
	              //多联网单位
	       		 	  if (single_Orgid == "") {
	       		 		  self.orgIds=userInfor.organizationIds;
	       		 	  } else {
	       		 		  self.orgIds=single_Orgid;
	       		 	  }
		       	  }
	            self.reInit();
	            self.gatUnitList();
			}
		},
		on : {
			pageInit : function(e, page) {
				var self = this;
				self.htmlPage();
				//重现筛选条件
                if(localStorage.getItem("ilink_select_option")){
                    var selectHistory = JSON.parse(localStorage.getItem("ilink_select_option"));
                    if(selectHistory.page == "filesLib"){
                        self.orgIds = selectHistory.organizationIds;
                        jQuery("#select_org").html(selectHistory.orgName).addClass('select-active');
                    }
                }
				self.gatUnitList();
			},
			pageBeforeOut: function(e, page) {
                var self = this;
                if(self.orgIds != userInfor.organizationIds){
                    let params = {
                        page:'filesLib',
                        organizationIds:self.orgIds,
                        orgName:jQuery("#select_org").html(),
                    }
                    saveSelectOption(params);
                }
            }
		}
	}
</script>